package com.qfmy.web.app.config;

import com.qfmy.common.Ai.SiliconCloud;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Lazy;
import org.springframework.http.HttpHeaders;
import org.springframework.http.MediaType;
import org.springframework.web.reactive.function.client.WebClient;

/**
 * @author 清风明月
 * @Package com.qfmy.web.app.config
 * @date 2025/10/21
 * @description webClient的配置类
 */
@Lazy
@Configuration
@EnableConfigurationProperties(SiliconCloud.class)
public class WebClientConfig {

    /**
     * 注入模型配置类
     */
    @Autowired
    private SiliconCloud siliconCloud;

    /**
     * 创建webClient
     * @return
     */
    @Bean
    public WebClient webClient(){
        WebClient webClient = WebClient.builder().
                baseUrl(siliconCloud.getUrl())
                .defaultHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON_VALUE)
                .defaultHeader(HttpHeaders.AUTHORIZATION, "Bearer " + siliconCloud.getApiKey())
                .build();
        return webClient;
    }

}
